export const DI = {
    ids: new Map(),
    TARGET: '$di$target',
    DEPENDENCIES: '$di$dependencies',
    getDep(ctor) {
        return ctor[DI.DEPENDENCIES] || [];
    },
};
function storeServiceDep(id, target, index) {
    const t = target;
    if (t[DI.TARGET] === target) {
        t[DI.DEPENDENCIES].push({ id, index });
    }
    else {
        t[DI.DEPENDENCIES] = [{ id, index }];
        t[DI.TARGET] = target;
    }
}
export function createDiWrapper(serviceId) {
    if (DI.ids.has(serviceId)) {
        return DI.ids.get(serviceId);
    }
    const id = function (target, key, index) {
        if (arguments.length !== 3) {
            throw new Error('DI: Decorator can only be used on a parameter');
        }
        storeServiceDep(id, target, index);
    };
    id.toString = () => `@inject(${serviceId})`;
    DI.ids.set(serviceId, id);
    return id;
}
